package com.panopset.game.blackjack;

public class Hand extends Total {

    private final BlackjackConfig c;
    private final Bankroll br;

    private int chips;
    private boolean doubleDowned = false;

    public void setDoubleDowned(final boolean value) {
        doubleDowned = value;
    }

    public boolean isDoubleDowned() {
        return doubleDowned;
    }

    public int getChips() {
        return chips;
    }

    public void clearHandChips() {
        chips = 0;
    }

    public void setHandChips(final int value) {
        if (chips != 0) {
            br.bet(-chips);
        }
        chips = value;
        br.bet(chips);
    }

    private String msg;

    public Hand(final int wager, final BlackjackConfig config, final Bankroll bankroll) {
        super();
        br = bankroll;
        c = config;
        setHandChips(wager);
    }

    public void setMessage(final String message) {
        msg = message;
    }

    public String getMessage() {
        if (msg == null) {
            msg = "";
        }
        return msg;
    }

    private boolean sa = false;

    public void setSplitAce(boolean resplitAcesAllowed) {
        sa = true;
        if (cards.get(1).isAce() && resplitAcesAllowed) {
            // still alive.
        } else {
            stand();
        }
    }

    public boolean isSplitAce() {
        return sa;
    }

    public boolean canDouble() {
        if (!isInitialDeal()) {
            return false;
        }
        if (hasSplit) {
            return c.isDoubleAfterSplitAllowed();
        } else {
            return true;
        }
    }
}
